package com.jy.admin.rest.response;

import com.fqgj.common.utils.CollectionUtils;
import com.jy.admin.db.entity.BogLogEntity;
import com.jy.admin.db.entity.PendingLogEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: sm
 * Date: 2021/12/27
 * Time: 5:05 下午
 */
public class ReplyListResponse {

    private static final Logger LOGGER = LoggerFactory.getLogger(ReplyListResponse.class);

    private List<Item> data = new ArrayList<>();


    public ReplyListResponse(List<PendingLogEntity> replyList) {

        if (CollectionUtils.isEmpty(replyList)) {
            return;
        }

        replyList.forEach(re -> {
            String replyDetail = re.getRequstDetail() + "\r\n\r\n" + re.getResultContent();
            LOGGER.info("== replyDetail ==,data:{}", replyDetail);

            data.add(new Item().setGroup(re.getFromGroup()).setReplyContent(replyDetail));
        });
    }

    public List<Item> getData() {
        return data;
    }


    public ReplyListResponse setData(List<Item> data) {
        this.data = data;
        return this;
    }

    private class Item {

        private String group;

        private String replyContent;


        public String getGroup() {
            return group;
        }

        public Item setGroup(String group) {
            this.group = group;
            return this;
        }

        public String getReplyContent() {
            return replyContent;
        }

        public Item setReplyContent(String replyContent) {
            this.replyContent = replyContent;
            return this;
        }
    }

    public static void main(String[] args) {

        try {
            String keep_on = URLEncoder.encode("keep on", "UTF-8");
            System.err.println(keep_on);


            System.err.println(URLDecoder.decode(keep_on, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }


    }
}
